package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.player.*;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

public class VehiclePb {

	public static VehicleProto.VehicleSkillTempMsg.Builder parseVehicleSkillTempMsg(UserVehicleSkill vehicleSkill) {
		if(null == vehicleSkill){
			return null;
		}
		VehicleProto.VehicleSkillTempMsg.Builder skillMsg = VehicleProto.VehicleSkillTempMsg.newBuilder();
		skillMsg.setSkillPos(vehicleSkill.getSkillPos());
		skillMsg.setSkillType(vehicleSkill.getSkillType());
		skillMsg.setSkillModifyTimes(vehicleSkill.getSkillModifyTimes());
		skillMsg.setValue(vehicleSkill.getValue());
		skillMsg.setRandomSkillType(vehicleSkill.getRandomSkillType());
		skillMsg.setRandomValue(vehicleSkill.getRandomValue());
		return skillMsg;
	}

	public static VehicleProto.VehicleOtherSkillTempMsg.Builder parseVehicleOtherSkillTempMsg(UserVehicleOtherSkill vehicleOtherSkill) {
		if(null == vehicleOtherSkill){
			return null;
		}
		VehicleProto.VehicleOtherSkillTempMsg.Builder skillMsg = VehicleProto.VehicleOtherSkillTempMsg.newBuilder();
		skillMsg.setSkillId(vehicleOtherSkill.getSkillId());
		skillMsg.setType(vehicleOtherSkill.getSkillType());
		skillMsg.setSkillLv(vehicleOtherSkill.getSkillLv());
		return skillMsg;
	}

	public static VehicleProto.VehicleTempMsg.Builder parseVehicleTempMsg(UserVehicle userVehicle) {
		if(null == userVehicle){
			return null;
		}
		VehicleProto.VehicleTempMsg.Builder vehicleMsg = VehicleProto.VehicleTempMsg.newBuilder();
		vehicleMsg.setVehicleUid(userVehicle.getVehicleUid());
		vehicleMsg.setTemplateId(userVehicle.getTemplateId());
		vehicleMsg.setPatronsId(userVehicle.getPatronsId());
		vehicleMsg.setLevel(userVehicle.getLevel());
		vehicleMsg.setBreakLv(userVehicle.getBreakLv());
		vehicleMsg.setStudyLv(userVehicle.getStudyLv());
		vehicleMsg.setEquipTimes(userVehicle.getEquipTimes());
		vehicleMsg.setEquipBuyTimes(userVehicle.getEquipBuyTimes());
		vehicleMsg.setCreateTime(userVehicle.getCreateTime());
		vehicleMsg.setResetTimes(userVehicle.getResetTimes());
		if (null != userVehicle.getSkillMapEffect()) {
			for (UserVehicleSkill skill : userVehicle.getSkillMapEffect().values()) {
				VehicleProto.VehicleSkillTempMsg.Builder skillMsg = parseVehicleSkillTempMsg(skill);
				if(null != skillMsg) {
					vehicleMsg.addSkillList(skillMsg);
				}
			}
		}
		//新的技能
		if (null != userVehicle.getOtherSkillList()) {
			for (UserVehicleOtherSkill skill : userVehicle.getOtherSkillList()) {
				VehicleProto.VehicleOtherSkillTempMsg.Builder skillMsg = parseVehicleOtherSkillTempMsg(skill);
				if(null != skillMsg) {
					vehicleMsg.addOtherSkillList(skillMsg);
				}
			}
		}

		vehicleMsg.addAllOpenPoss(userVehicle.getSoulBlockList());
		vehicleMsg.setBoneLv(userVehicle.getBoneLv());
		vehicleMsg.setBoneHole(userVehicle.getBoneHole());
		return vehicleMsg;
	}

	public static VehicleProto.VehicleSimpleTempMsg.Builder parseVehicleSimpleTempMsg(UserVehicle userVehicle) {
		if(null == userVehicle){
			return null;
		}
		VehicleProto.VehicleSimpleTempMsg.Builder vehicleMsg = VehicleProto.VehicleSimpleTempMsg.newBuilder();
		vehicleMsg.setVehicleUid(userVehicle.getVehicleUid());
		vehicleMsg.setTemplateId(userVehicle.getTemplateId());
		vehicleMsg.setLevel(userVehicle.getLevel());
		vehicleMsg.setStudyLv(userVehicle.getStudyLv());
		return vehicleMsg;
	}

	public static VehicleProto.VehicleListMsg.Builder parseVehicleListMsg(List<UserVehicle> vehicleList) {
		VehicleProto.VehicleListMsg.Builder vehicleListMsg = VehicleProto.VehicleListMsg.newBuilder();
		if(null != vehicleList) {
			for (UserVehicle userVehicle : vehicleList) {
				if (!userVehicle.isDelete()) {
					VehicleProto.VehicleTempMsg.Builder vehicleMsg = parseVehicleTempMsg(userVehicle);
					if(null != vehicleMsg) {
						vehicleListMsg.addVehicleList(vehicleMsg);
					}
				}
			}
		}
		return vehicleListMsg;
	}

	public static VehicleProto.VehicleDetailMsg.Builder parseVehicleDetailMsg(UserVehicleDetail userVehicleDetail) {
		if(null == userVehicleDetail){
			return null;
		}
		VehicleProto.VehicleDetailMsg.Builder msg = VehicleProto.VehicleDetailMsg.newBuilder();
		msg.addAllTemplateIdList(userVehicleDetail.getTemplateIdList());
		return msg;
	}

	public static VehicleProto.RecycleLockStatusRespMsg.Builder buildRecycleLockStatusMsg(UserPassword userPassword) {
		VehicleProto.RecycleLockStatusRespMsg.Builder builder = VehicleProto.RecycleLockStatusRespMsg.newBuilder();
		builder.setIsLock(0);
		builder.setLockEndTime(0);
		if (null == userPassword) {
			return builder;
		}

		if (!StringUtils.isNullOrEmpty(userPassword.getRecyclePassword())){
			builder.setIsLock(1);
		}
		builder.setLockEndTime(userPassword.getLockRecycleEndTime());
		return builder;
	}
}
